#pragma once
#include "afxcmn.h"

#define TC_LIGHTBLACK	(RGB(40,40,40))
#define TC_GRAY		(RGB(200,200,200))
#define TC_RED		(RGB(200,20,20))
#define TC_GREEN	(RGB(20,200,20))
#define TC_BLUE		(RGB(20,20,240))
#define TC_YELLOW	(RGB(200,200,20))
#define TC_PINK		(RGB(200,20,200))

class CRichEditEx :	public CRichEditCtrl
{
public:

	CRichEditEx(void);
	virtual ~CRichEditEx(void);

	void Init();
	void Exit();
	void SetMaxLine(const int maxline=100);
	void SetTextColor(COLORREF crNewColor=RGB(0,0,0));
	void SetBkColor(COLORREF crNewColor=RGB(255,255,255));
	void SetAutoScroll(BOOL bAuto=TRUE);

	void Output(const TCHAR* str, ...); 
	void AddText(COLORREF color, const TCHAR* str, ...);
	void AllClear()
	{
		SetSel(0, -1);
		Clear();
	}
protected:
	CRITICAL_SECTION m_cs;
	INT m_nOldLine;
	INT m_nMaxLine;
	BOOL m_bAutoScrollEnd;
	COLORREF m_crTextColor;

	DECLARE_MESSAGE_MAP()

public:
	afx_msg void OnSetFocus(CWnd* pOldWnd);
};
